package com.example.printstream;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;

public class PrintStreamDemo2 {
    public static void main(String[] args) throws IOException {
        /**
         * 打印流
         * 字节打印流
         * 字符打印流
         */
        //1.创建字符打印流对象
        PrintWriter pw = new PrintWriter(new FileWriter("src/com/example/file/o.txt"), true);

        //2.写出数据
        pw.println("Hello World");

        //3.释放资源
        pw.close();

        PrintStream ps = new PrintStream(System.out);  // 将打印流连接到控制台

        /**
         * new PrintStream(ps);
         */
        ps.print("Hello, ");
        ps.print("World! ");  // 输出：Hello, World!

        ps.println("Welcome to Java.");
        ps.println("Enjoy coding!");  // 输出：Welcome to Java.\nEnjoy coding!\n

        ps.close();

    }
}
